/*
 * @Author: Liz.Zheng
 * @Date: 2021-09-24 16:23:18
 * @LastEditTime: 2022-07-15 17:34:11
 * @LastEditors: 郑亚莉 zhengyali@shequ.life
 * @Description:
 * @Motto: Write the code. Change the world.
 */
import { createApp } from "vue";
import App from "./App.vue";
import appUse from "./common/utils/app_use";
import actions from "./common/utils/action";
import store from "./store";
import utils from "./common/utils/utils";
import {router,history} from "./router";
import "ant-design-vue/dist/antd.less";
import "./common/styles/common.less";
import "./common/utils/permission";
import "./common/styles/global.css";
import defaultSetting from "./common/utils/defaultSetting";
import moment from "moment";
import duration from 'dayjs/plugin/duration';
import components from "./router/components";
import "./router-path";
import microApp from '@micro-zoe/micro-app'
moment.extend(duration);

let app = null;
window.mount=()=>{
  app = createApp(App)
  appUse(app)
  microApp.start({
    tagName:"micro-app-approval"
  })
  app.mount("#app")
}

// 👇 将卸载操作放入 unmount 函数，就是上面步骤2中的卸载函数
window.unmount = () => {
  app.unmount()
  history?.destroy()
  app = null
}

// 如果不在微前端环境，则直接执行mount渲染
if (!window.__MICRO_APP_ENVIRONMENT__) {
  window.mount();
}else {
  const  appData = window?.microApp?.getData()||{};
  const data = appData?.props||{};
  saveProps(data);
  if (data.appHeight){
    store.dispatch("SetAppHeight",data.appHeight);
  }
}


function saveProps(props = {}) {
  if (Object.keys(props).length) {
    window.ORGCOMMON_BASE_URL = props.customDomain;
    store.dispatch("SetMainAppProps", props).then((res) => {
      const { token } = res;
      // 取出token到vuex
      if (token) {
        store.dispatch("SetToken", token);
      }
    });
  }
}

